package com.pikaq.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pikaq.entity.Msg;
import com.pikaq.service.MsgService;
import com.pikaq.util.Util;

@RequestMapping("/msg")
@Controller
public class MsgController {

	@Resource
	private MsgService msgServiceImpl;
	
	@ResponseBody
	@RequestMapping("/insertMsg")
	public Map<String, Object> insertMsg(Msg msg,HttpServletRequest request){
		msg.setAddr(Util.getIpAddr(request));
		msgServiceImpl.insert(msg);
		Map<String,Object> result = new HashMap<String, Object>();
		result.put("success", false);
		return result;
	}
	
	@ResponseBody
	@RequestMapping("/getMsg")
	public List<Msg> getMsg(){
		List<Msg> msgs= msgServiceImpl.getMsg();
		
		return msgs;
	}
}
